//editRoleCtrl

app.controller('newUserCtrl', function($element, $scope, $state, rest, user, uploadConf, tipService, $window, $rootScope) {
	var token = $window.localStorage.getItem("token");
	$scope.iNowData = {
		"loginName":"",
		"userName":"",
		"loginPwd":"",
		"reloginPwd":"",
		"mobile":"",
		"email":"",
		"jobNumber":""
	}
	
    $scope.preserveSubmit = function(){
    	var btn = true;
    	if($scope.iNowData.loginName == ""){
    		layer.tips('账户必填', '.loginName-Tips',{
			    tipsMore: true,
			    tips: [2,'#ed5565']
			});
			btn = false;
    	};
    	if($scope.iNowData.userName == ""){
    		layer.tips('姓名必填', '.userName-Tips',{
			    tipsMore: true,
			    tips: [2,'#ed5565']
			});
			btn = false;
    	};
    	/*if($scope.iNowData.loginPwd == ""){
    		layer.tips('密码必填', '.loginPwd-Tips',{
			    tipsMore: true,
			    tips: [2,'#ed5565']
			});
			btn = false;
    	};
    	if($scope.iNowData.reloginPwd == ""){
    		layer.tips('确认密码必填', '.reloginPwd-Tips',{
			    tipsMore: true,
			    tips: [2,'#ed5565']
			});
			btn = false;
    	};*/
    	if($scope.iNowData.mobile == ""){
    		layer.tips('手机必填', '.mobile-Tips',{
			    tipsMore: true,
			    tips: [2,'#ed5565']
			});
			btn = false;
    	};
    	if($scope.iNowData.email == ""){
    		layer.tips('邮箱必填', '.email-Tips',{
			    tipsMore: true,
			    tips: [2,'#ed5565']
			});
			btn = false;
    	};
    	if(btn){
    		rest.decoJava({
    			type: 'post',
	            url: '/tenancy-sys/admin/user/add', 
	            data: JSON.stringify($scope.iNowData),
	            contentType: "application/json; charset=utf-8",
	            beforeSend: function(request){
					request.setRequestHeader("token", token); 
				},
	            success: function (result) {
	            	layer.closeAll('loading');
	            	console.log(result)
	                if (result) {
	                    if ("0000" == result.code) {
							layer.msg(result.message, {
					        	offset:'t',
					        	icon: 1,
								time: 0, //不自动关闭
								btn: ['确定'],
								yes: function(index){
									layer.close(index);
									$scope.closeThisDialog();
							    }
							});
	                    } else {
	                    	layer.msg(result.message,{
			    				offset:'t'
			    			});
	                    }
	                }
	            }
	        })
    	}
    };
    
    $scope.hideBtn = function(){
    	$scope.closeThisDialog();
    }
    
});
